from rest_framework import serializers
from ..models import DataDictionary, DataDictionaryDetail


class DictSerializer(serializers.ModelSerializer):
    '''
    字典序列化
    '''
    id = serializers.IntegerField(label='id', read_only=True)
    dict_id = serializers.CharField(max_length=50, source='DataDictionaryId')
    label = serializers.CharField(max_length=50, source='FullName')
    parent_id = serializers.CharField(max_length=50, required=False, allow_blank=True, allow_null=True, source='ParentId')
    dict_code = serializers.CharField(max_length=50, required=False, allow_blank=True, allow_null=True, source='DictionaryCode')
    remark = serializers.CharField(required=False, allow_blank=True, allow_null=True, source='Remark')
    is_enabled = serializers.BooleanField(required=False, label='是否可用', source='IsEnabled')

    create_id = serializers.IntegerField(label='创建人id', required=False, source='CreateByUid')
    create_user = serializers.CharField(label='创建人', max_length=50, required=False, source="AddByName")
    create_date = serializers.DateTimeField(label='创建时间', required=False, source="AddDate")
    update_id = serializers.IntegerField(label='修改人id', required=False, source='UpdateByUid')
    update_user = serializers.CharField(label='更新人', max_length=50, required=False, source="UpdateByName")
    update_date = serializers.DateTimeField(label='更新时间', required=False, source="UpdateDate")

    class Meta:
        model = DataDictionary
        fields = ['id', 'dict_id', 'label', 'parent_id', 'dict_code', 'is_enabled', 'remark','create_id', 'create_user',
                  'create_date', 'update_id', 'update_user', 'update_date']


class DictDetailSerializer(serializers.ModelSerializer):
    '''
    字典详情序列化
    '''
    id = serializers.IntegerField(label='id', read_only=True)
    dict_id = serializers.CharField(label='字典id', max_length=50, required=False, allow_blank=True, allow_null=True, source='DataDictionaryId')
    dict_detail_id = serializers.CharField(label='字典详情id', max_length=50, required=False, allow_blank=True, allow_null=True, source='DataDictionaryDetailId')
    label = serializers.CharField(label='字典名称', max_length=300, allow_null=True, source='FullName')
    remark = serializers.CharField(label='备注', max_length=300, required=False, allow_blank=True, allow_null=True, source='Remark')
    parent_id = serializers.CharField(label='父类字典', required=False, allow_blank=True, allow_null=True, max_length=50, source='ParentId')
    dict_code = serializers.CharField(label='键', max_length=50, source='DictionaryCode')
    dict_val = serializers.CharField(label='值', max_length=50, source='DictionaryValue')
    parent_code = serializers.CharField(label='字典id', required=False, allow_blank=True, allow_null=True, max_length=50, source='ParentCode')
    is_enabled = serializers.BooleanField(label='是否可用', required=False, source='IsEnabled')
    sort_no_two = serializers.IntegerField(label='查策网排序', required=False, source='SortNoTwo')
    create_id = serializers.IntegerField(label='创建人id', required=False, source='CreateByUid')
    create_user = serializers.CharField(label='创建人', max_length=50, required=False, source="AddByName")
    create_date = serializers.DateTimeField(label='创建时间', required=False, source="AddDate")
    update_id = serializers.IntegerField(label='修改人id', required=False, source='UpdateByUid')
    update_user = serializers.CharField(label='更新人', max_length=50, required=False, source="UpdateByName")
    update_date = serializers.DateTimeField(label='更新时间', required=False, source="UpdateDate")

    class Meta:
        model = DataDictionaryDetail
        fields = ['id', 'dict_id', 'dict_detail_id', 'label', 'remark', 'parent_id',
                  'dict_code', 'dict_val', 'is_enabled', 'parent_code', 'create_id', 'create_user',
                  'create_date', 'update_id', 'update_user', 'update_date', 'sort_no_two'
                  ]
